package com.lc.zpyh.adapter;

import android.os.Bundle;

import com.lc.zpyh.R;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class MainActivityDemo extends AppCompatActivity {

    private CountDownAdapter countDownAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maindemo);

        RecyclerView recyclerView = findViewById(R.id.recyclerView);

        countDownAdapter = new CountDownAdapter(getCountDownList());
        countDownAdapter.setGetTime(System.currentTimeMillis());
        recyclerView.setAdapter(countDownAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    }

    protected List<CountDownEntity> getCountDownList() {
        List<CountDownEntity> countDownEntities = new ArrayList<>();

        for (int i = 0; i < 40; i++) {
            CountDownEntity countDownEntity = new CountDownEntity();
            countDownEntity.setId(i);
            countDownEntity.setTitle("==" + i);
            countDownEntity.setTime(20000);
            countDownEntity.setTimev(i == 0 || i == 2);
            countDownEntities.add(countDownEntity);
        }

        return countDownEntities;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        countDownAdapter.cancelAllTimers();
    }
}